using System;
using System.Collections;
using System.Drawing;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using System.Net;
using System.Net.Cache;
using System.IO;
using System.Web;
using System.Xml;
using System.Runtime.CompilerServices;
using System.Diagnostics;

using ZoneFiveSoftware.Common.Visuals;

using Dimebrain.TweetSharp.Fluent;
using Dimebrain.TweetSharp.Extensions;
using BENBUN.Properties;
using BENBUN.Utils;

namespace BENBUN.ST_Twitter
{
    public partial class OptionsView : UserControl
    {

        public OptionsView()
        {
            InitializeComponent();
            textBoxUsername.Text = Settings.Settings.TwitterScreenName;
            textBoxPassword.Text = Settings.Settings.TwitterPassword;

            checkSTTag.Checked = Settings.Settings.TwitterSTTag;

            checkCustomTag.Checked = Settings.Settings.TwitterCustomTagEnabled;
            textCustomTag.Text = Settings.Settings.TwitterCustomTag;
            
        }

        public IPageStatus Status
        {
            get { return null; }
        }

        public bool Modified
        {
            get { return false; }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void ShowPage(string bookmark)
        {
            bIgnoreCtrlChanges = true;
            bIgnoreCtrlChanges = false;

        }

        public bool HidePage()
        {
            return true;
        }

        public void ThemeChanged(ITheme visualTheme)
        {
            BackColor = visualTheme.Control;
        }

        public void UICultureChanged(CultureInfo culture)
        {
        }

        #region Event handlers



        #endregion

        private bool bIgnoreCtrlChanges = false;

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            var twitter = FluentTwitter.CreateRequest()
                    .Users().ShowProfileFor("BENBUN")
                    .Request();


            var user = twitter.AsUser();

            Console.WriteLine("User's geo enabled status: {0}", user.IsGeoEnabled);
        }

        private void textBoxUsername_TextChanged(object sender, EventArgs e)
        {
            Settings.Settings.TwitterScreenName = textBoxUsername.Text;
            Settings.Settings.save();
        }

        private void textBoxPassword_TextChanged(object sender, EventArgs e)
        {
            Settings.Settings.TwitterPassword = textBoxPassword.Text;
            Settings.Settings.save();
        }

        private void checkSTTag_CheckedChanged(object sender, EventArgs e)
        {
            Settings.Settings.TwitterSTTag = checkSTTag.Checked;
            Settings.Settings.save();
        }

        private void textCustomTag_TextChanged(object sender, EventArgs e)
        {
            string tag = textCustomTag.Text;

            if (!tag.StartsWith("#"))
            {
                tag = "#" + tag;
            }

            Settings.Settings.TwitterCustomTag = tag;
            Settings.Settings.save();
        }

        private void checkCustomTag_CheckedChanged(object sender, EventArgs e)
        {
            textCustomTag.Enabled = checkCustomTag.Enabled;
            Settings.Settings.TwitterCustomTagEnabled = checkCustomTag.Enabled;
        }

        private void checkBox1_Enter(object sender, EventArgs e)
        {
            textBoxUsername.Text = Settings.Settings.TwitterScreenName;
            textBoxPassword.Text = Settings.Settings.TwitterPassword;

            checkSTTag.Enabled = Settings.Settings.TwitterSTTag;

            checkCustomTag.Enabled = Settings.Settings.TwitterCustomTagEnabled;
            textCustomTag.Text = Settings.Settings.TwitterCustomTag;

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Process.Start(BENBUN.Properties.Resources.Paypal);
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }


    }
}
